using Godot;

[GlobalClass]
public partial class DataItem : Resource
{
    private float _value;
    
    [Export] public float MinVal;
    [Export] public float MaxVal;

    [Export]
    public float Value
    {
        get => _value;
        set
        {
            value = Mathf.Clamp(value, MinVal, MaxVal);
            if (Mathf.IsEqualApprox(value, _value)) return;
            var old = _value;
            _value = value;
            EmitSignal(SignalName.ValueChanged, old, _value);
        }
    }

    [Signal]
    public delegate void ValueChangedEventHandler(float ov, float nv);

    public DataItem() : base()
    {
    }

    public DataItem(float min, float max, float val)
    {
        MinVal = min;
        MaxVal = max;
        Value = val;
    }
}